<template>
	<view class="content">
		<scroll-view style="height: calc(100vh);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view class="hei20"></view>	
			<view class="wid90 mar">
				<swiper class="wid100 borRad20 mar-top20" style="height: 273rpx;" circular :autoplay='true'>
					<swiper-item v-for="(item,index) in banner.split(',')" :key="index">
						<image :src="url+'/addon/qianyu_petrol/wxapp/image/fxsq.jpg  '" class="wh100 borRad20"></image>
					</swiper-item>
				</swiper>
			</view>
			<view class="mar-top30 textCen fowe600 foSi40" style="color: #37BCC3;">- 精品推荐 -</view>
			<view class="wid90 mar dis disAl disJuB flwa">
				<block v-for="(item,index) in list" :key="index">
					<view class="borRad20 bacFFF mar-top30" @click="tiaozhuan('/pages/commodity/commodity?id='+item.id)"
						style="width: 49%;box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);padding-bottom: 20rpx;">
						<view class="wid100"style="height: 267rpx;">
							<image :src="url+item.pic.split(',')[0]" class="wh100"
								style="border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;"></image>
						</view>
						<view class="wid90 mar mar-top10">
							<view class="foSi20 fowe800 yclh">{{item.name}}</view>
							<view class="dis disJuB foSi20 mar-top10" style="align-items: flex-end;">
								<view>
									<view class="dis disAl">
										<view class="fowe600 foSi25" style="color: #37BCC3;">¥{{item.price}}</view>
										<view class="foSi18 poRel mar-left20" style="color: #858887;">
											<span>¥{{item.old_price}}</span>
											<view class="poAbs wid100" style="background-color: #858887;height: 1rpx;top: 12rpx;"></view>
										</view>
									</view>
									<view class="mar-top10 foSi18" style="color: #585858;">已售{{item.sell_num}}</view>
								</view>
								<image src="../../static/gwowuche.png" style="width: 45rpx;height: 45rpx;"></image>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				list: [],
				last_page: 0,
				page: 1,
				banner: ''
			}
		},
		onLoad() {
			this.getBanner()
		},
		onShow() {
			this.page = 1
			this.getList()
		},
		methods: {
			getBanner(){
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_shop_banner',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id: uni.getStorageSync('jiaId')
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.banner = result.data
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_goods',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						is_type: 1,
						page: that.page,
						limit: 10,
						type_id: 0,
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {}
	
</style>
